package cn.com.pajx.pajx_visitor_v3.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.pajx.facelibrary.utils.DensityUtil;
import com.rcw.swiperefreshrecyclerview.BaseAdapter;
import com.rcw.swiperefreshrecyclerview.ViewHolder;

import java.util.List;

import cn.com.pajx.pajx_visitor_v3.R;
import cn.com.pajx.pajx_visitor_v3.bean.VisiteBean;
import cn.com.pajx.pajx_visitor_v3.ui.view.TextureOutlineProvider;
import cn.com.pajx.pajx_visitor_v3.utils.BaseImageUtils;
import cn.com.pajx.pajx_visitor_v3.utils.CornerTransform;
import cn.com.pajx.pajx_visitor_v3.utils.DateUtil;

/**
 * Created by ruancw on 2024/2/28.
 * Description: 拜访历史记录（拜访中，结束拜访）
 */
public class VisiteHistoryAdapter extends BaseAdapter<VisiteBean> {

    public VisiteHistoryAdapter(Context context, int layoutId, List<VisiteBean> datas) {
        super(context, layoutId, datas);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ViewHolder holder, VisiteBean bean, int position) {
        ImageView ivPhoto = holder.getView(R.id.iv_avatar);
        TextView tvNo = holder.getView(R.id.tv_no);
        TextView tvVisitor = holder.getView(R.id.tv_visitor);
        TextView tvVisitorPhone = holder.getView(R.id.tv_visitor_phone);
        TextView tvInterviewee = holder.getView(R.id.tv_visitor_object);
        TextView tvStatus = holder.getView(R.id.tv_visitor_status);
        TextView tvOrderTime = holder.getView(R.id.tv_order_time);
        TextView tvInTime = holder.getView(R.id.tv_in_time);
        TextView tvOutTime = holder.getView(R.id.tv_out_time);
        //Glide设置圆角图片
        CornerTransform transform = new CornerTransform(context, DensityUtil.dp2px(context, 8));
        transform.setCornerRadius(false, false, false, false);
        if (TextUtils.isEmpty(bean.getVis_photo())) {
            BaseImageUtils.setLocalCornerImage(context, ivPhoto, R.mipmap.icon_avatar_big, transform);
        } else {
            BaseImageUtils.setNetCornerImage(context, ivPhoto, bean.getVis_photo(), R.mipmap.icon_avatar_big, transform);
        }
        ivPhoto.setOutlineProvider(new TextureOutlineProvider(DensityUtil.dp2px(context, 8)));
        ivPhoto.setClipToOutline(true);
        tvNo.setText((position + 1) + "");
        tvVisitor.setText(TextUtils.isEmpty(bean.getVis_name_des()) ? bean.getVis_name() : bean.getVis_name_des());
        tvInterviewee.setText(TextUtils.isEmpty(bean.getUser_name_des()) ? bean.getUser_name() : bean.getUser_name_des());
        tvOrderTime.setText(DateUtil.getYMDHMTime(bean.getTime_plan()));
        tvVisitorPhone.setText(bean.getVis_phone_des());
        tvInTime.setText(DateUtil.getYMDHMTime(bean.getTime_act()));
        tvOutTime.setText(DateUtil.getYMDHMTime(bean.getTime_end()));
        String visite_status = bean.getVis_status();
        if (TextUtils.isEmpty(visite_status)) visite_status = "999";
        switch (visite_status) {
            case "0"://待审批
                tvStatus.setText("待审批");
                tvStatus.setTextColor(context.getResources().getColor(R.color.colorOrange));
                tvStatus.setBackgroundResource(R.drawable.shape_status_approve);
                break;
            case "1"://待拜访
                tvStatus.setText("待拜访");
                tvStatus.setTextColor(context.getResources().getColor(R.color.colorGreen));
                tvStatus.setBackgroundResource(R.drawable.shape_status_waiting);
                break;
            case "2"://拒绝拜访
                tvStatus.setText("拒绝拜访");
                tvStatus.setTextColor(context.getResources().getColor(R.color.colorRed));
                tvStatus.setBackgroundResource(R.drawable.shape_status_reject);
                break;
            case "3"://拜访中
                tvStatus.setText("拜访中");
                tvStatus.setTextColor(context.getResources().getColor(R.color.colorBlue27));
                tvStatus.setBackgroundResource(R.drawable.shape_status_visiting);
                break;
            case "4"://结束拜访
                tvStatus.setText("拜访结束");
                tvStatus.setTextColor(context.getResources().getColor(R.color.colorOrange22));
                tvStatus.setBackgroundResource(R.drawable.shape_status_finish);
                break;
            default://已失效
                tvStatus.setText("已失效");
                tvStatus.setTextColor(context.getResources().getColor(R.color.colorGrey90));
                tvStatus.setBackgroundResource(R.drawable.shape_status_invalid);
                break;
        }

    }
}
